﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TracNghiemV1.Utilities
{
    class Utils
    {
        public const int USER_ID_LENGHT = 10;

        public const int COURSE_ID_LENGHT = 10;

        public const int TOPIC_ID_LENGHT = 20;


        public static string GenerateId(int count, int lenght)
        {
            string tempString = (count + 1).ToString();
            int currentLenght = tempString.Length;
            string resultString = "";

            for (int i = lenght; i > currentLenght; i--)
            {
                resultString += "0";
            }
            resultString += tempString;

            return resultString;
        }

        public static int FistIndexOfNoneZero(string id)
        {
            for (int i = id.Length - 1; i > 0 ; i--)
            {
                if (id[i] != '0')
                {
                    return i;
                }
            }
            return 0;
        }

        public static string GenerateId(string latestId, int lenght)
        {
            string tempString = (int.Parse(latestId) + 1).ToString();
            int currentLenght = tempString.Length;
            string resultString = "";

            for (int i = lenght; i > currentLenght; i--)
            {
                resultString += "0";
            }
            resultString += tempString;

            return resultString;
        }
    }
}
